Skip to content

Add missing SessionContext utility methods#1475

Draft
timsaucer wants to merge 1 commit intoapache:mainfrom
timsaucer:feat/add-utility-methods
Draft

Add missing SessionContext utility methods#1475
timsaucer wants to merge 1 commit intoapache:mainfrom
timsaucer:feat/add-utility-methods

Conversation

@timsaucer
Copy link
Copy Markdown
Member

Which issue does this PR close?

Closes #1459

Rationale for this change

These methods exist in the upstream repository but have not been exposed to Python.

What changes are included in this PR?

Add methods to the Python API
Add unit tests

Are there any user-facing changes?

New addition only.

Expose upstream DataFusion v53 utility methods: session_start_time,
enable_ident_normalization, parse_sql_expr, execute_logical_plan,
refresh_catalogs, remove_optimizer_rule, and table_provider. The
add_optimizer_rule and add_analyzer_rule methods are omitted as the
OptimizerRule and AnalyzerRule traits are not yet exposed to Python.
Closes apache#1459.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR exposes additional SessionContext utility/introspection methods in the datafusion-python API to match capabilities available in upstream DataFusion v53 (Issue #1459), and adds unit tests to cover the new Python surface area.

Changes:

  • Added Python SessionContext wrappers for: session_start_time, enable_ident_normalization, parse_sql_expr, execute_logical_plan, refresh_catalogs, remove_optimizer_rule, and table_provider.
  • Added corresponding Rust binding methods on PySessionContext to call into DataFusion v53 APIs.
  • Added unit tests validating the new Python methods.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
python/datafusion/context.py Adds new SessionContext methods to the public Python API and wraps internal bindings (Expr, DataFrame, Table).
crates/core/src/context.rs Exposes the underlying DataFusion SessionContext methods via the PyO3 PySessionContext bindings.
python/tests/test_context.py Adds tests for the newly exposed SessionContext methods.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1090 to +1091
let provider = wait_for_future(py, self.ctx.table_provider(name))??;
Ok(PyTable { table: provider })
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table_provider() currently propagates DataFusion errors directly. For consistency with table() (which maps missing-table errors to KeyError), consider translating the “No table named …” / not-found case here to PyKeyError as well so Python users get a consistent exception type when looking up a non-existent table provider.

Suggested change
let provider = wait_for_future(py, self.ctx.table_provider(name))??;
Ok(PyTable { table: provider })
match wait_for_future(py, self.ctx.table_provider(name))? {
Ok(provider) => Ok(PyTable { table: provider }),
Err(err) => {
let err_msg = err.to_string();
if err_msg.contains("No table named") || err_msg.contains("not found") {
Err(pyo3::exceptions::PyKeyError::new_err(err_msg))
} else {
Err(err.into())
}
}
}

Copilot uses AI. Check for mistakes.
Comment on lines +1145 to +1152
def session_start_time(self) -> str:
"""Return the session start time as an RFC 3339 formatted string."""
return self.ctx.session_start_time()

def enable_ident_normalization(self) -> bool:
"""Return whether identifier normalization (lowercasing) is enabled."""
return self.ctx.enable_ident_normalization()

Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says it closes #1459, but the issue’s checklist also includes add_optimizer_rule and add_analyzer_rule. Those methods still don’t appear to be exposed in either the Rust bindings or the Python wrapper (no references found in the repo). Either add the remaining methods or adjust the PR description / linked issue closure to reflect the reduced scope.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add missing SessionContext utility methods

2 participants